package cn.gotom.pinggu.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import cn.gotom.coding.EncodingUtils;
import cn.gotom.core.service.UniversalService;
import cn.gotom.core.web.Constants;
import cn.gotom.core.web.action.MenuInf;
import cn.gotom.pinggu.pojos.Cppw;
import cn.gotom.pinggu.pojos.Cpzl;
import cn.gotom.pinggu.pojos.CsffEnum;
import cn.gotom.pinggu.pojos.Whzl;
import cn.gotom.pinggu.pojos.Yjczz;
import cn.gotom.pinggu.pojos.Ylpw;

import com.google.inject.Inject;

public class YjczzAction implements MenuInf
{
	protected final Logger log = Logger.getLogger(getClass());

	public String input()
	{
		yjczz = null;
		return Constants.LIST;
	}

	public String save()
	{
		if (StringUtils.isNotEmpty(yjczz.getId()))
		{
			EncodingUtils.encoding(yjczz, "GBK", "cp850");
			yjczz = (Yjczz) universalService.persist(yjczz);
		}
		return Constants.LIST;
	}

	public String remove()
	{
		log.debug("remove id=" + yjczz.getId());
		yjczz = universalService.get(Yjczz.class, yjczz.getId());
		if (yjczz != null)
		{
			universalService.remove(yjczz);
		}
		return Constants.LIST;
	}

	public String list()
	{
		yjczzList = universalService.findAll(Yjczz.class);
		cpzlList = universalService.findAll(Cpzl.class);
		for (Object r : cpzlList)
		{
			EncodingUtils.encoding(r, "cp850", "GBK");
		}
		cppwList = universalService.findAll(Cppw.class);
		for (Object r : cppwList)
		{
			EncodingUtils.encoding(r, "cp850", "GBK");
		}
		ylpwList = universalService.findAll(Ylpw.class);
		for (Object r : ylpwList)
		{
			EncodingUtils.encoding(r, "cp850", "GBK");
		}
		whzlList = universalService.findAll(Whzl.class);
		for (Object r : whzlList)
		{
			EncodingUtils.encoding(r, "cp850", "GBK");
		}
		csffList = CsffEnum.values();
		if (yjczz != null)
		{
			yjczz = universalService.get(Yjczz.class, yjczz.getId());
		}
		else
		{
			yjczz = new Yjczz();
		}
		for (Object r : yjczzList)
		{
			EncodingUtils.encoding(r, "cp850", "GBK");
		}
		return Constants.SUCCESS;
	}

	@Override
	public String getName()
	{
		return "预警参照值";
	}

	@Override
	public String getGroupName()
	{
		return "代码表管理";
	}

	@Override
	public int getMenuSort()
	{
		return 300;
	}

	@Inject
	private UniversalService universalService;

	private Yjczz yjczz;

	private List<Yjczz> yjczzList;

	private List<Cpzl> cpzlList;

	private List<Cppw> cppwList;

	private List<Ylpw> ylpwList;

	private List<Whzl> whzlList;

	private CsffEnum[] csffList;

	public Yjczz getYjczz()
	{
		return yjczz;
	}

	public void setYjczz(Yjczz yjczz)
	{
		this.yjczz = yjczz;
	}

	public List<Yjczz> getYjczzList()
	{
		return yjczzList;
	}

	public void setYjczzList(List<Yjczz> yjczzList)
	{
		this.yjczzList = yjczzList;
	}

	public List<Cpzl> getCpzlList()
	{
		return cpzlList;
	}

	public void setCpzlList(List<Cpzl> cpzlList)
	{
		this.cpzlList = cpzlList;
	}

	public List<Cppw> getCppwList()
	{
		return cppwList;
	}

	public void setCppwList(List<Cppw> cppwList)
	{
		this.cppwList = cppwList;
	}

	public List<Ylpw> getYlpwList()
	{
		return ylpwList;
	}

	public void setYlpwList(List<Ylpw> ylpwList)
	{
		this.ylpwList = ylpwList;
	}

	public List<Whzl> getWhzlList()
	{
		return whzlList;
	}

	public void setWhzlList(List<Whzl> whzlList)
	{
		this.whzlList = whzlList;
	}

	public CsffEnum[] getCsffList()
	{
		return csffList;
	}

	public void setCsffList(CsffEnum[] csffList)
	{
		this.csffList = csffList;
	}

}
